<template>
  <div :class="{ 'ly-is-full': isFull }">
    <div class="tableSelect" ref="tableSelect">
      <div v-show="searchMoreType">
        <screen :formInline="formInline" ref="RefScreen"></screen>
      </div>

      <el-form :inline="true" :model="formInline" label-position="right">
        <el-row :gutter="20" type="flex">
          <el-col :span="20">
            <el-form-item label="">
              <el-input
                v-model.trim="formInline.school_name"
                maxlength="60"
                clearable
                placeholder="学校名称"
                style="width: 200px"
              ></el-input>
              <el-button @click="search" type="primary" icon="Search"
                >查询</el-button
              ></el-form-item
            >
            <el-form-item label=""
              ><el-button @click="handleEdit('', 'reset')" icon="Refresh"
                >重置</el-button
              ></el-form-item
            >
            <!-- <el-form-item label=""
              ><el-button @click="addModule" type="primary"
                >添加-模版</el-button
              ></el-form-item
            >
            <el-form-item label=""
              ><el-button
                @click="addModuleShool"
                v-if="authority([1, 2])" 
                type="primary"
                >添加</el-button
              ></el-form-item
            > -->
            <!-- <el-form-item label=""
            v-if="authority([1, 2])" 
              ><el-button @click="handleDelete" type="danger"
                >删除</el-button
              ></el-form-item
            > -->
            <el-form-item label=""
              ><el-button @click="exportText" type="primary"
                >导出</el-button
              ></el-form-item
            >

            <!-- <el-form-item label=""
              ><el-button @click="exportText" type="primary"
                >一键排课</el-button
              ></el-form-item> -->
            <!-- <el-form-item label=""
              ><el-upload
                class="upload-demo"
                :on-preview="handlePreview"
                :action="`${$config.API_URL}common/upload/`"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                multiple
                accept=".xls,.xlsx"
                :on-change="handleChange"
                :on-exceed="handleExceed"
                :on-success="handleSuccess"
                :file-list="fileList"
                :show-file-list="false"
              >
                <el-button 
                v-if="authority([1, 2])" 
                type="primary">导入</el-button>
              </el-upload></el-form-item
            > -->
          </el-col>

          <el-form-item label-width="170">
            <el-button
              v-if="searchMoreType"
              @click="searchMore"
              type="primary"
              icon="Minus"
              style="margin-left: 20px"
              >收回查询</el-button
            >

            <el-button
              v-if="!searchMoreType"
              @click="searchMore"
              type="primary"
              icon="Aim"
              style="margin-left: 20px"
              >查询更多</el-button
            >
          </el-form-item>
        </el-row>

        <!-- <el-form-item label=""><el-button @click="handleDelete" type="danger" :disabled="multiple" v-show="isShowBtn('goodsType','商品分类','Delete')">删除</el-button></el-form-item> -->
      </el-form>
    </div>

    <div class="table">
      <el-table
        :height="tableHeight"
        border
        :data="tableData"
        v-loading="loadingPage"
        style="width: 100%"
        ref="tableref"
        @selection-change="handleSelectionChange"
        row-key="id"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <!--                <el-table-column type="selection" width="55"></el-table-column>-->
        <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column>
        <el-table-column type="index" width="60" align="center" label="序号">
          <template #default="scope">
            <span v-text="getIndex(scope.$index)"></span>
          </template>
        </el-table-column>
        
        <!-- 排序修改 开始 -->
        <el-table-column min-width="150" prop="status" label="核校状态">
          <template #default="scope">
            <el-text v-if="scope.row.status == 1" class="mx-1" type="warning"
              >未核校</el-text
            >

            <el-text v-if="scope.row.status == 2" class="mx-1" type="primary"
              >已核校</el-text
            >
            <el-text v-if="scope.row.status == 3" class="mx-1" type="danger"
              >已驳回</el-text
            >
            <el-text v-if="scope.row.status == 4" class="mx-1" type="success"
              >已通过</el-text
            >
            <el-text v-if="scope.row.status == 5" class="mx-1" type="danger"
              >问题校</el-text
            >
          </template>
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="province"
          label="省"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="city"
          label="所在城市"
        ></el-table-column>
        <el-table-column
          min-width="150"
          prop="county"
          label="所在区县"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="school_name"
          label="学校名称"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="school_type"
          label="学校类别"
        ></el-table-column>

        <el-table-column
          min-width="100"
          prop="school_num"
          label="学校人数"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="class_num"
          label="班级个数"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="teacher_num"
          label="教师人数"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="director_name"
          label="学校该项目负责人姓名"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="director_phone"
          label="学校该项目负责人电话"
        ></el-table-column>
        <el-table-column
          min-width="150"
          prop="job"
          label="职务"
        ></el-table-column>
        <el-table-column
          min-width="180"
          prop="instrument"
          
          label="学校是否有直播工具"
          
        >
          <template #default="scope" >
            <el-tag type="primary" v-if="scope.row.instrument == '1'"
              >是</el-tag
            >
            <el-tag type="danger" v-if="scope.row.instrument == '2'">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          min-width="200"
          prop="grade"
          label="年级"
        ></el-table-column>
        <el-table-column
          min-width="150"
          prop="class_name"
          label="班级"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="course"
          label="课程"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="some"
          label="第几节"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="week"
          label="周几"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="tart_time"
          label="上课时间"
        ></el-table-column>
        <el-table-column
          min-width="100"
          prop="end_time"
          label="下课时间"
        ></el-table-column>

        <el-table-column
          min-width="150"
          prop="num_time"
          label="实际上课时间"
        ></el-table-column>
        <el-table-column
          min-width="150"
          prop="zuser_name"
          label="在地老师名称"
        ></el-table-column>
        <el-table-column
          min-width="150"
          prop="user_phone"
          label="联系电话"
        ></el-table-column>
        <el-table-column min-width="100" prop="class_mode" label="班级规模">
        </el-table-column>
        <el-table-column
          min-width="130"
          prop="admission_time"
          label="入校时间"
        ></el-table-column>
        <el-table-column
          min-width="200"
          prop="zxuser_name"
          label="在线区域负责人名称"
        >
        </el-table-column>
        <el-table-column
          min-width="200"
          prop="user_name"
          label="在地工作人员名称"
        ></el-table-column>

       
        <el-table-column min-width="100" prop="is_status" label="是否排课">
        </el-table-column>
        <el-table-column min-width="150" prop="images" label="入校照片">
          <template #default="scope">
            <div v-if="scope.row.images">
              <el-image
                v-for="(item, index) in scope.row.images"
                :z-index="99999999"
                :preview-teleported="true"
                :key="index"
                style="width: 30px; height: 30px"
                :src="item"
                :preview-src-list="[item]"
              ></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column min-width="150" prop="videos" label="入校视频">
          <template #default="scope">
            <el-button
              v-if="scope.row.video"
              @click="rowUrl(scope.row.video)"
              type="primary"
              icon="Search"
              >查看</el-button
            >
          </template>
        </el-table-column>

        <el-table-column min-width="180" prop="createtime" label="资料下载">
          <template #default="scope">
            <span class="table-operate-btn" @click="loadPZip(scope.row)"
              >图片下载</span
            >
            <span class="table-operate-btn" @click="loadVZip(scope.row)"
              >视频下载</span
            >
          </template>
        </el-table-column>
        <el-table-column
          min-width="180"
          prop="createtime"
          label="创建时间"
        ></el-table-column>
         <!-- 排序修改 结束-->
      </el-table>
      <el-dialog title="制定入校计划" v-model="inSchooleVis" width="500">
        <el-form :model="planForm">
          <el-form-item label="入校时间" :label-width="formLabelWidth">
            <el-input v-model="planForm.admission_time" autocomplete="off" />
          </el-form-item>
          <el-form-item label="备注原因" :label-width="formLabelWidth">
            <el-input
              v-model="planForm.reason_remark"
              style="width: 440px"
              :rows="2"
              type="textarea"
              placeholder="请输入备注原因"
            />
          </el-form-item>

          <el-form-item label="入校计划" prop="state">
            <el-select
              v-model="planForm.state"
              placeholder="入校计划"
              clearable
              style="width: 300px"
              @change="planT($event)"
            >
              <el-option
                v-for="item in inSchoolPlan"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <template #footer>
          <el-button @click="handleClose" :loading="loadingSave"
            >取消</el-button
          >
          <el-button
            type="primary"
            @click="submitData"
            :loading="loadingSave"
            :disabled="loadingTitle == '详情'"
            >确定</el-button
          >
        </template>
      </el-dialog>

      <el-dialog
        title="添加入校资料"
        v-model="inSchooleTextVis"
        width="700"
        @close="diaClose"
      >
        <el-form :model="addSchoolPlanForm">
          <el-form-item label="学校照片" :label-width="100">
            <el-upload
              class="upload-demo"
              :action="`${$config.API_URL}common/upload/`"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :on-success="handleAvatarSuccess"
              accept=".png,.jpeg,.jpg"
              multiple
              :on-exceed="handleChangesImage"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="学校视频" :label-width="100">
            <el-upload
              class="upload-demo"
              :action="`${$config.API_URL}common/upload/`"
              :on-preview="handlePreview"
              :on-remove="handleRemoveVideo"
              :before-remove="beforeRemove"
              :on-success="handleAvatarSuccessVideo"
              accept=".mp4,.ogg,.flv,.avi,.wmv,.rmvb,.mov"
              multiple
              :on-exceed="handleChangesImage"
              :file-list="videoList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="其他材料信息" :label-width="100">
            <el-input
              v-model="addSchoolPlanForm.description"
              style="width: 440px"
              :rows="2"
              type="textarea"
              placeholder="请输入其他材料信息"
            />
          </el-form-item>
        </el-form>

        <template #footer>
          <el-button @click="handleClose" :loading="loadingSave"
            >取消</el-button
          >
          <el-button
            type="primary"
            @click="submitDataS"
            :loading="loadingSave"
            :disabled="loadingTitle == '详情'"
            >确定</el-button
          >
        </template>
      </el-dialog>

      <el-dialog v-model="videoDialogVisible" width="80%" top="5vh">
        <el-carousel height="900px">
          <el-carousel-item
            v-for="(item, index) in currentVideoUrl"
            :key="index"
          >
            <video
              :src="item"
              controls
              style="width: 100%"
              autoplay="autoplay"
            ></video>
          </el-carousel-item>
        </el-carousel>
      </el-dialog>
    </div>
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <add-module-goods-type
      ref="addModuleFlag"
      @refreshData="refreshData"
    ></add-module-goods-type>

    <!-- 在地区域管理员操作 -->
    <addModuleShool ref="addModuleShool" @refreshData="refreshData">
    </addModuleShool>
    <!-- 在地工作人员提交学校信息 -->
    <editModuleShool
      ref="editModuleShool"
      @refreshData="refreshData"
    ></editModuleShool>
  </div>
</template>
<script>
import Pagination from "@/components/Pagination.vue";
import { dateFormats } from "@/utils/util";
import "video.js/dist/video-js.css";
import {
  schoolList,
  schoolDel,
  adminGroup,
  schoolImport,
  rstaffschoolAdd,
  addschool,
  schoolExport,
  schoolEdit,
  schoolUpdate,
} from "@/api/api";
import XEUtils from "xe-utils";
import AddModuleGoodsType from "./components/add.vue"; //普通新增
import addModuleShool from "./components/addShool.vue";
import editModuleShool from "./components/editShool.vue";
import { lyMixins } from "@/mixins/mixins";
import dayjs from "dayjs";
import { setStorage, getStorage } from "@/utils/util";
import axios from "axios";
import { saveAs } from "file-saver";
import ExcelJS from "exceljs";
import screen from "@/components/screen/screen.vue";
  import { ElMessage, ElMessageBox, ElLoading } from "element-plus";

export default {
  mixins: [lyMixins],
  components: {
    AddModuleGoodsType,
    addModuleShool,
    editModuleShool,
    screen,
    Pagination,
  },
  name: "adminManage",
  data() {
    return {
      state: 4, //状态为
      is_status: 2, //1未排课 2已排课
      currentVideoUrl: [], // 当前视频链接
      videoDialogVisible: false,
      options: {
        autoplay: false, // 设置自动播放
        muted: true, // 设置了它为true，才可实现自动播放,同时视频也被静音
        preload: "auto", // 预加载
        controls: true, // 显示播放的控件
      },
      searchMoreType: false,
      fileList: [],
      videoList: [],
      planForm: {
        id: "",
        admission_time: "",
        reason_remark: "",
        status: "",
      },
      addSchoolPlanForm: {
        id: "",
        images: [],
        videos: [],
        description: "",
      },
      inSchoolPlan: [
        {
          value: "1",
          label: "待审核",
          id: "1",
        },
        {
          value: "2",
          label: "已审核",
          id: "2",
        },
      ],
      inSchooleVis: false,
      inSchooleTextVis: false,
      isFull: false,
      loadingPage: false,
      // 选项框选中数组
      ids: [],

      // 选项框非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      formInline: {
        page: 1,
        page: 1,
        per_page: 10,
      },
      pageparm: {
        page: 1,
        per_page: 10,
        total: 0,
      },
      statusList: [
        { id: 1, name: "正常" },
        { id: 0, name: "禁用" },
      ],
      timers: [],
      tableData: [],
      selectData: [],
      GroupList: [], //管理员分组列表
      planList: [
        {
          value: "1",
          label: "待制定",
          id: "1",
        },
        {
          value: "2",
          label: "已制定",
          id: "2",
        },
      ],
      isStatusList: [
        {
          value: "1",
          label: "未排课",
          id: "1",
        },
        {
          value: "2",
          label: "已排课",
          id: "2",
        },
      ],
      inSchoolPlan: [
        {
          value: "1",
          label: "待审核",
          id: "1",
        },
        {
          value: "2",
          label: "已审核",
          id: "2",
        },
      ],
      linePlanList: [
        {
          value: "1",
          label: "是",
          id: "1",
        },
        {
          value: "2",
          label: "否",
          id: "2",
        },
      ],
      images: "",
      userInfo: "", //用户权限字段
    };
  },
  methods: {
    openOk(e) {
      let vm = this;
      console.log(e, "---------schoolUpdate");
      // 确认排课
      this.$confirm("确定进行排课确认吗？", "排课确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let objs = {
          id: e.id,
          is_status: "已排课",
        };
        schoolUpdate(objs).then((res) => {
          vm.getData();
        });
      });
    },
    authority(groupArr = [0]) {
      // 权限筛选
      let userInfo = this.userInfo;
      // 当前权限和传来的权限组进行对比
      if (groupArr.some((item) => Number(item) === userInfo)) return true;
      return false;
    },
    rowUrl(url) {
      this.currentVideoUrl = url;
      this.videoDialogVisible = true; // 显示对话框
    },
    diaClose() {
      this.fileList = [];
      this.videoList = [];
    },
    searchMore() {
      this.searchMoreType = !this.searchMoreType;
    },
    search(i, e) {
      this.formInline.page = 1;
      this.formInline.per_page = 10;
     let objs = this.$refs.RefScreen?.formInline||{};
      this.formInline = { ...this.formInline, ...objs };
      this.getData();
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handlePreview(file) {
      console.log(file);
    },
    loadPZip(e) {
      if (!e.images || e.images.length == 0){
        return ElMessage.error("入校照片暂未上传");
      }
      axios({
        url: this.$config.API_URL+"school/imageszip/", // 后端提供的 ZIP 文件下载 URL
        method: "POST",
        responseType: "blob", // 重要，这会返回一个 Blob 对象
        data: {
          id: e.id,
        },
      })
        .then((response) => {
          const url = URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement("a");
          link.href = url;
          link.download = `${e.school_name}${e.grade}${e.class_name}-图.Zip`; // 设置下载文件名
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
          URL.revokeObjectURL(url); // 释放URL对象
        })
        .catch((e) => {
          console.error("下载失败:", e);
        });
    },
    loadVZip(e) {
      if (!e.video || e.video.length == 0){
        return ElMessage.error("入校视频暂未上传！！！");
      }

      axios({
        url: this.$config.API_URL+"school/videozip/", // 后端提供的 ZIP 文件下载 URL
        method: "POST",
        responseType: "blob", // 重要，这会返回一个 Blob 对象
        data: {
          id: e.id,
        },
      })
        .then((response) => {
          const url = URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement("a");
          link.href = url;
          link.download = `${e.school_name}${e.grade}${e.class_name}-视频.Zip`; // 设置下载文件名
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
          URL.revokeObjectURL(url); // 释放URL对象
        })
        .catch((e) => {
          console.error("下载失败:", e);
        });
    },
    exportText(e) {
      if (this.ids.length == 0) {
        ElMessage.error("请先选择导出数据");
        return;
      }
      axios({
        url: this.$config.API_URL+"school/export/",
        method: "post", //请求方法
        responseType: "blob", //表示接受服务器返回的二进制流
        data: {
          id: this.ids,
        },
      })
        .then((res) => {
          console.log(res);

          let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
          let fileName = "学校核销表"; // 自定义文件名
          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            // IE兼容
            window.navigator.msSaveOrOpenBlob(blob, fileName);
          } else {
            let objectUrl = (window.URL || window.webkitURL).createObjectURL(
              blob
            );
            let downloadLink = document.createElement("a");
            downloadLink.href = objectUrl;
            downloadLink.download = fileName;
            document.body.appendChild(downloadLink);
            downloadLink.click();
            document.body.removeChild(downloadLink);
            window.URL.revokeObjectURL(objectUrl); // 释放URL对象
          }
        })
        .catch((error) => {
          ElMessage.error("导出失败");
        });
    },
    handleAvatarSuccess(res, file) {
      this.fileList.push({
        name: res.data.url,
        url: res.data.url,
      });
    },
    handleAvatarSuccessVideo(res, file) {
      this.videoList.push({
        name: res.data.url,
        url: res.data.url,
      });
    },
    handleChangesImage(e) {},
    beforeAvatarUpload(file) {
      const isJPG =
        file.type === "image/jpeg" ||
        file.type === "image/jpg" ||
        file.type === "image/png";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        ElMessage.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        ElMessage.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    handleClose() {
      this.inSchooleVis = false;
      this.inSchooleTextVis = false;
    },
    submitData() {
      rstaffschoolAdd({ ...this.planForm }).then((res) => {
        if (res.code == 1) {
          ElMessage({
            showClose: true,
            message: "制定成功",
            type: "success",
          });
          this.getData();
          this.inSchooleVis = false;
        }
      });
    },

    submitDataS() {
      this.addSchoolPlanForm.images = this.fileList.map((item) => {
        return item.url;
      });
      this.addSchoolPlanForm.videos = this.videoList.map((item) => {
        return item.url;
      });
      console.log(this.addSchoolPlanForm);
      addschool({ ...this.addSchoolPlanForm }).then((res) => {
        if (res.code == 1) {
          ElMessage({
            showClose: true,
            message: "添加成功",
            type: "success",
          });
          this.getData();
          this.inSchooleTextVis = false;
        }
      });
    },
    planT(e) {
      this.planForm.status = this.inSchoolPlan.find(
        (item) => item.value == e
      ).value;
    },
    formatDateTime(time) {
      return dayjs.unix(time).format("YYYY-MM-DD HH:mm");
    },
    refreshData(x) {
      // 新增成功 搜索归0
      if (x) this.handleEdit("", "reset");
      else this.getData();
    },
    setFull() {
      this.isFull = !this.isFull;
      window.dispatchEvent(new Event("resize"));
    },
    // 表格序列号
    getIndex($index) {
      // (当前页 - 1) * 当前显示数据条数 + 当前行数据的索引 + 1
      return (this.pageparm.page - 1) * this.pageparm.per_page + $index + 1;
    },
    //多选项框被选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      console.log(this.ids, "选中项");
    },
    /** 批量删除按钮操作 */
    handleDelete(row) {
      const ids = this.ids;
      if (ids.length == 0) {
        ElMessage.warning("请选择要删除数据");
        return;
      }
      let vm = this;
      vm.$confirm("是否确认删除选中的数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function () {
        return schoolDel({ ids: ids }).then((res) => {
          if (res.code == 1) {
            ElMessage.success(res.msg);
            vm.search();
          } else {
            ElMessage.warning(res.msg);
          }
        });
      });
    },
    changeStatus(row) {
      console.log(row, "row----");
    },
    addModule(row) {
      // 普通全部新增
      console.log(this.GroupList, "---------新增出发");
      this.$refs.addModuleFlag.addModuleFn(row, "新增", this.GroupList);
    },
    // 在地提交学校信息
    editshows(row) {
      this.$refs.editModuleShool.addModuleFn(
        row,
        "学校信息提交",
        this.GroupList
      );
    },
    addModuleShool() {
      // 学校新增
      this.$refs.addModuleShool.addModuleFn(null, "学校新增", this.GroupList);
    },
    handleEdit(row, flag) {
      if (flag == "detail") {
        this.$refs.addModuleFlag.addModuleFn(row, "详情", this.GroupList);
      } else if (flag == "edit") {
        if (this.authority([2]))
          this.$refs.addModuleShool.addModuleFn(
            row,
            "重新发布",
            this.GroupList
          );
        else this.$refs.addModuleFlag.addModuleFn(row, "编辑", this.GroupList);
      } else if (flag == "delete") {
        let vm = this;
        vm.$confirm("您确定要删除选中的数据吗？", {
          closeOnClickModal: false,
        })
          .then((res) => {
            schoolDel({ id: row.id }).then((res) => {
              if (res.code == 1) {
                ElMessage.success(res.msg);
                vm.search();
              } else {
                ElMessage.warning(res.msg);
              }
            });
          })
          .catch(() => {});
      } else if (flag == "reset") {
        // 清空组件
        this.$refs.RefScreen.reset();
        this.formInline = {
          page: 1,
          per_page: 10,
        };
        this.pageparm = {
          page: 1,
          per_page: 10,
          total: 0,
        };
        this.getData();
      }
    },

    callFather(parm) {
      this.formInline.page = parm.page;
      this.formInline.per_page = parm.per_page;
      this.getData();
    },
    //获取列表
    async getData() {
      this.loadingPage = true;
      this.formInline.status = this.state; //驳回
      this.formInline.is_status = this.is_status; //驳回

      schoolList(this.formInline).then((res) => {
        this.loadingPage = false;
        if (res.code == 1) {
          this.tableData = res.data.data;
          // // 将列表数据转换为树形数据
          // this.tableData = XEUtils.toArrayTree(res.data.data, { parentKey: 'parent', strict: false })
          this.pageparm.page = res.data.current_page;
          this.pageparm.per_page = res.data.per_page;
          this.pageparm.total = res.data.total;
        }
      });
    },

    timeChange(val) {
      if (val) {
        this.formInline.beginAt = dateFormats(val[0], "yyyy-MM-dd hh:mm:ss");
        this.formInline.endAt = dateFormats(val[1], "yyyy-MM-dd hh:mm:ss");
      } else {
        this.formInline.beginAt = null;
        this.formInline.endAt = null;
      }
      this.search();
    },
    getGroupList() {
      // 管理员分组获取
      adminGroup().then((res) => {
        if (res.code == 1) {
          //console.log(res, "------------成功获取到管理员分组列表");
          this.GroupList = res.data;
        }
      });
    },
    handleRemove(file, fileList) {
      this.fileList = this.fileList.filter((item) => {
        return item.name != file.name;
      });
      console.log(this.fileList);
    },
    handleRemoveVideo(file, fileList) {
      this.videoList = this.videoList.filter((item) => {
        return item.name != file.name;
      });
      console.log(this.videoList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleSuccess(res, file) {
      if (res.code == 1) {
        schoolImport({ file: res.data.url }).then((res) => {
          if (res.code == 1) {
            this.getData();
            ElMessage.success(`导入成功`);
          }else {
            ElMessage.error(res.msg);
          }
        });
      }
    },
    handleExceed(files, fileList) {
      console.log(files, fileList, "111");
      return;
      ElMessage.warning(
        `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    // 文件状态改变时
    handleChange(file) {
      // 结构获取文件名
      let { name } = file;
      // 正则校验文件格式
      let result = /^.xls|.png|.xlsx$/.test(
        // 截取文件名后缀 例：.zip
        // 注解：
        // substring() 截取字符串中介于两个指定下标之间的字符
        // toLowerCase()  将字符串转换为小写
        // lastIndexOf(".") 返回一个指定的字符串值最后出现的位置
        name.substring(name.lastIndexOf(".")).toLowerCase()
      );
      if (!result) {
        ElMessage.error("上传文件格式不符合要求");
        return;
      }
    },
    // 制定计划
    order(e) {
      this.inSchooleVis = true;
      this.planForm.id = e.id;
    },
    // 添加入校资料
    addPlan(e) {
      schoolEdit({ id: e.id }).then((res) => {
        if (res.code == 1) {
          if (res.data.images) {
            this.fileList = res.data.images.map((item) => {
              return {
                name: item,
                url: item,
              };
            });
          }
          if (res.data.video) {
            this.videoList = res.data.video.map((item) => {
              return {
                name: item,
                url: item,
              };
            });
          }
        }
      });
      this.inSchooleTextVis = true;
      this.addSchoolPlanForm.id = e.id;
    },
  },
  created() {
    this.userInfo = Number(JSON.parse(getStorage("groupId"))); //权限

    // 获取管理员分组
    this.getGroupList();
    // 数据获取
    this.getData();
  },
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.video-box {
  width: 100%;
  max-width: 500px;
  max-height: 500px;
}
::v-deep .video-js .vjs-big-play-button {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
